<?php
session_start();
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
require_once "config.php";
require_once "Includes/conexion.class.php";

$CboNodo = $_REQUEST["CboNodo"];
$orden = $_REQUEST["TxtDescPA"];
if (empty($orden)) $orden = 1;
//'response.write $_REQUEST["id")&","&$_REQUEST["ds")&","&$_REQUEST["ds2")&","&$_REQUEST["ds3")&","&$_REQUEST["ds4")
//'response.end
$Atributos = "";//'$_REQUEST["ATxtDescAt")
$MaxId = SoloFun_Maximo("co_modu","solotb_modulo");
$tabla = "solotb_modulo";

if ($_REQUEST["hidId"] != "") {
    switch( $_REQUEST["Opcion"]) {
        case 1:
            $tipo = "UPDATE";

            $strSql = "$tipo $tabla set ";
            $strSql .= "ds_modu='" . $_REQUEST["TxtDesc"] . "', ";
            $strSql .= "no_prog='" . trim($orden) . "' ";
            $strSql .= " where co_modu =" . $_REQUEST["hidId"]  . " and nodo = " . $_REQUEST["CboNodo"];
            //$_REQUEST["ds3"] = $_REQUEST["TxtDesc"];
            break;
        case 2:
            $strsql = "select count(*) from solotb_modulo_transaccion where co_modu=". $_REQUEST["hidId"];
            SoloFun_ExecSql ($strsql, $SoloArrModulosTran);
            if ($SoloArrModulosTran[0][0] <> "0")
                $err = 2;
            else {
                $err = 0;
                $tipo = "DELETE";
                $strSql = "$tipo from $tabla where co_modu =" . $_REQUEST["hidId"] . " and nodo = " . $_REQUEST["CboNodo"];
            }
            break;
        case 3:
            $tipo = "INSERT";
            $strSql = "$tipo into $tabla(co_modu,ds_modu, nodo,ds_atrib,no_prog) values (";
            $strSql .= $_REQUEST["hidId"] . ",'";
            $strSql .= $_REQUEST["TxtDesc"] . "',";
            $strSql .= $_REQUEST["CboNodo"] . ",'"	;
            $strSql .= $_REQUEST["TxtDescAt"] . "','";
            $strSql .= $orden . "')";
            break;
    }
//echo $strSql;
    $arrQueries = array();
    array_push($arrQueries, $strSql);
    array_push($arrQueries, crearQueryLog($tabla, $tipo, $strSql));
    $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
            $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
//printArray($arrQueries);
    //if(!$oConexion->EjecutarQuery($strSql)) {
    if(!$oConexion->EjecutarTransaccion($arrQueries)) {
        $strMsg = "solotrn_GrabarModulo.php?SoloError=1&CboNodo=".$CboNodo;
        //echo $oConexion->getErrorMessage();
    }else
    // 'strMsg="solotrn_AdministrarModulo.asp?SoloError=0&CboNodo="&CboNodo
        $strMsg = "solotrn_GrabarModulo.php?SoloError=0&CboNodo=$CboNodo&Opcion=".$_REQUEST["Opcion"] . "&id=". $_REQUEST["hidId"]. "&ds=". $_REQUEST["TxtDesc"];

    if ($err == 2) {
        $message = "El M&oacute;dulo no puede eliminarse, realiza transacciones";
        $strMsg = "solotrn_GrabarModulo.php?SoloError=$message&CboNodo=$CboNodo&Opcion=".$_REQUEST["Opcion"] . "&id=". $_REQUEST["hidId"]. "&ds=". $_REQUEST["TxtDesc"];
    }
    $oConexion->Cerrar();

    header("Location: $strMsg");
}

$band = false;
switch ($_REQUEST["Opcion"]) {
    case 1:
        $imagen= "iconos/soloico_grabar.gif";
        $etiqueta="Modificar M&oacute;dulo";
        $oculto="<input type='hidden' name='Opcion' value=1>";
        $titulo="Modificar M&oacute;dulo";
        break;
    case 2:
        $imagen = "iconos/soloico_eliminar.gif";
        $etiqueta = "Eliminar M&oacute;dulo";
        $oculto = "<input type='hidden' name='Opcion' value=2>";
        $titulo = "Eliminar de M&oacute;dulo";
        break;
    case 3:
        $imagen = "iconos/soloico_grabar.gif";
        $etiqueta = "Ingresar M&oacute;dulo";
        $oculto = "<input type='hidden' name='Opcion' value=3>";
        $titulo="Ingresar M&oacute;dulo";
        break;
    case 0:
        $imagen = "iconos/soloico_consultar.gif";
        $etiqueta = "Consultar M&oacute;dulo";
        $titulo = "Consultar M&oacute;dulo";
        $strSql = "select * from solotb_modulo_transaccion where co_modu=" . $_REQUEST["id"]. " and nodo = " . $_REQUEST["CboNodo"]. " order by ds_tran";
        $oculto = "<input type='hidden' name='Opcion' value=0>";
        $display = "Style='display: none'";
        SoloFun_ExecSql ($strSql, $arrData);
        $band = true;
        break;
}
?>
<html>
    <head>
        <title>MIES-WORKFLOW - M&oacute;dulos</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" href="SoloStyles/Solostyles.css" type="text/css">
    </head>

    <body topmargin=0 leftmargin=0>
        <table cellpadding="0" cellspacing="0" style="width: 90%">
            <tr>
                <td><img src="templates/SoloTemplate_LogoCabecera.png" style="height: 50px" alt=""/></td>
                <td style="text-align:center" class="SoloStyle_TituloPaginas"><?php echo $titulo;?></td>
            </tr>
        </table>
        <br/>
        <?php if ($_REQUEST["Opcion"] <> 4) {?>
        <form name="frmIngreso" action="solotrn_GrabarModulo.php" method="POST">
            <table border="0" width="80%" align="center" cellpadding="2" cellspacing="1" bordercolor="#CCCCCC">
                <tr>
                    <td><?php if ($_REQUEST["Opcion"] <> 0) {

                            }?>
                        <img src="iconos/soloico_salir.gif" border="1" alt="Regresar" style="cursor:hand" onClick="window.opener.location.reload(); window.close();" >
                        <img src="<?php echo $imagen;?>" border="1" alt="<?php echo $etiqueta;?>" style="cursor:hand" onClick="frmIngreso.submit();">      </td>
            </table>
            <table <?php echo $display;?>border="1" width="80%" align="center" bordercolor="#CCCCCC" cellpadding="0" cellspacing="1">
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Id</b></td>
                        <?php
                        switch($_REQUEST["Opcion"]) {
                            case 0:
                            case 1:
                            case 2:
                                $idid = $_REQUEST["id"];
                                break;
                            case 3:
                                $idid = $MaxId;
                                break;
                        }
                        ?>
                    <td class="SoloStyle_EtiquetaCajas"><?php echo $idid;?>
                        <input type="hidden" maxlength="50" size="30" name="hidId" class="texto" value="<?php echo $idid;?>"></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Descripci&oacute;n</b></td>
                    <td class="SoloStyle_EtiquetaCajas">
                        <input type="text" maxlength="50" size="30" name="TxtDesc" class="SoloStyle_Texto" value="<?php echo $_REQUEST["ds"];?>">
                        <input type="hidden" name="CboNodo" size="5" class="texto" value="<?php echo $CboNodo;?>"></td>
                </tr>
                <tr style="display:none">
                    <td class="SoloStyle_Etiqueta">Empresa</td>
                    <td class="SoloStyle_EtiquetaCajas">
                        <input type="text" maxlenght="10" size="10" name="hidcbonodo" class="SoloStyle_Texto" value="<?php //'$_REQUEST["CboNodo"];?>"></td>
                </tr>
                <tr style="display:none">
                    <td class="SoloStyle_Etiqueta"><b>Atributos</b></td>
                    <td class="SoloStyle_EtiquetaCajas">
                        <input type="text" maxlenght="50" size="50" name="TxtDescAt" class="SoloStyle_Texto" value="<?php echo $_REQUEST["ds2"];?>"></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Orden</b></td>
                    <td class="SoloStyle_EtiquetaCajas">
                        <input type="text" maxlength="5" size="30" name="TxtDescPA" class="SoloStyle_Texto" value="<?php echo $_REQUEST["ds3"];?>"></td>
                </tr>
            </table>
            <br><center><?php echo $oculto;?></center>
        </form>
            <?php if ($_REQUEST["Opcion"] == 0) { ?>
        <table width="80%" border="1" align="center" bordercolor="#CCCCCC" cellpadding="2" cellspacing="1">
            <tr class="etiqueta">
                <td class="SoloStyle_TablaTitulo">M&oacute;dulo: <?php echo $_REQUEST["ds"];?></td>
            </tr>
                    <?php
                    if ($band) {
                        for ($i = 0; $i < count($arrData); $i++) {
                            $clase = "SoloStyle_texto";
                            if ($i%2 == 0)
                                $clase = "SoloStyle_Grid";
                            ?>
            <tr>
                <td class="<?php echo $clase;?>"><?php echo $arrData[$i][2];?></td>
            </tr>
                            <?php }
                    }
                } ?>
        </table>
        <br><center><?php echo $BOTON;?><?php echo $oculto;?></center>
            <?php }
//'DataConn.close()?>
    </body>
</html>
<?php
include "Includes/soloFun_ShowMessages.php";
?>
